package com.cloud.dao.impl;

import java.util.List;

import org.apache.ibatis.session.SqlSession;
import org.springframework.stereotype.Component;

import com.cloud.core.BaseDao;
import com.cloud.dao.DoctorBean;
import com.cloud.dao.DoctorInfo;
import com.cloud.dao.HospitalBean;
import com.cloud.dao.InvestigatorsBean;
import com.cloud.dao.PatientBean;
import com.cloud.dao.ProjectBean;

/**
 * 1Cloud1
 * @author Administrator
 * @since 2015-12-4
 * @version 1.0 
 */
@Component("DoctorDao")
public class DoctorDao extends BaseDao {
	
	public List<DoctorInfo> queryDoctorContact(DoctorBean bean){
		SqlSession session = super.getInstance(true);
		List<DoctorInfo> beanList = null;
		try {
			beanList = session.selectList("doctor.queryDoctorContact", bean);
		} catch (Exception e) {
			e.printStackTrace();
			return null;
		} finally {
			session.close();
		}
		return beanList;
	}
	
	public List<String> queryDoctorIdList(DoctorBean bean){
		SqlSession session = super.getInstance(true);
		List<String> beanList = null;
		try {
			beanList = session.selectList("doctor.queryDoctorIdList", bean);
		} catch (Exception e) {
			e.printStackTrace();
			return null;
		} finally {
			session.close();
		}
		return beanList;
	}
	
	public List<DoctorInfo> queryDoctor(DoctorBean bean){
		SqlSession session = super.getInstance(true);
		List<DoctorInfo> beanList = null;
		try {
			beanList = session.selectList("doctor.queryDoctor", bean);
		} catch (Exception e) {
			e.printStackTrace();
			return null;
		} finally {
			session.close();
		}
		return beanList;
	}
	
	public List<DoctorBean> getDoctorList(DoctorBean bean){
		SqlSession session = super.getInstance(true);
		List<DoctorBean> beanList = null;
		try {
			beanList = session.selectList("doctor.list", bean);
		} catch (Exception e) {
			e.printStackTrace();
			return null;
		} finally {
			session.close();
		}
		return beanList;
	}
	
	public void addDoctor(DoctorBean bean){
		SqlSession session = super.getInstance(true);
		session.insert("doctor.insert", bean);
		session.close();
	}
	
	/**
	 * 修改医生
	 * @param bean
	 */
	public void updateDoctor(DoctorBean bean){
		SqlSession session = super.getInstance(true);
		session.update("doctor.update", bean);
		session.close();
	}
	
	/**
	 * 删除医生
	 * @param bean
	 */
	public void deleteDoctor(DoctorBean bean){
		SqlSession session = super.getInstance(true);
		session.delete("doctor.delete", bean);
		session.close();
	}
	
	public List<ProjectBean> queryProjectByPatient(PatientBean bean){
		SqlSession session = super.getInstance(true);
		List<ProjectBean> beanList = null;
		try {
			beanList = session.selectList("project.queryProjectByPatient", bean);
		} catch (Exception e) {
			e.printStackTrace();
			return null;
		} finally {
			session.close();
		}
		return beanList;
	}
	
	/**
	 * 获取医生所在项目
	 * @param bean
	 * @return
	 */
	public List<ProjectBean> queryProjectByDoctor(DoctorBean bean){
		SqlSession session = super.getInstance(true);
		List<ProjectBean> beanList = null;
		try {
			beanList = session.selectList("project.queryProjectByDoctor", bean);
		} catch (Exception e) {
			e.printStackTrace();
			return null;
		} finally {
			session.close();
		}
		return beanList;
	}
	
	public List<HospitalBean> queryHospitalByPro(String pro_id){
		SqlSession session = super.getInstance(true);
		List<HospitalBean> beanList = null;
		try {
			beanList = session.selectList("project.queryHospitalByPro", pro_id);
		} catch (Exception e) {
			e.printStackTrace();
			return null;
		} finally {
			session.close();
		}
		return beanList;
	}
	
	public List<DoctorBean> queryDoctorByProHos(InvestigatorsBean bean){
		SqlSession session = super.getInstance(true);
		List<DoctorBean> beanList = null;
		try {
			beanList = session.selectList("project.queryDoctorByProHos", bean);
		} catch (Exception e) {
			e.printStackTrace();
			return null;
		} finally {
			session.close();
		}
		return beanList;
	}
	
	public List<PatientBean> queryPatientByProHos(InvestigatorsBean bean){
		SqlSession session = super.getInstance(true);
		List<PatientBean> beanList = null;
		try {
			beanList = session.selectList("project.queryPatientByProHos", bean);
		} catch (Exception e) {
			e.printStackTrace();
			return null;
		} finally {
			session.close();
		}
		return beanList;
	}
	
	public String queryCrcByDoctorProject(InvestigatorsBean bean){
		SqlSession session = super.getInstance(true);
		String crc = "";
		try {
			crc = session.selectOne("project.queryCrcByDoctorProject", bean);
		} catch (Exception e) {
			e.printStackTrace();
			return null;
		} finally {
			session.close();
		}
		return crc;
	}
}
